//初始值
export const initState = {
    userInfo:sessionStorage.getItem("userInfo")?JSON.parse(sessionStorage.getItem("userInfo")):{}
}

//修改state 
export const reducer = (state, action) => {
    switch (action.type) {
        //{type:"changeUserInfo",userInfo:{token:"1"}}
        case "changeUserInfo":
            return {
                ...state,
                userInfo: action.userInfo
            }
        default:
            return state;
    }
}
//actionCreator 
export const actions = {
    changeUserInfo: (userInfo) => {
        if(userInfo.token){
            sessionStorage.setItem("userInfo",JSON.stringify(userInfo))
        }else{
            sessionStorage.removeItem("userInfo")
        }
        return { type: "changeUserInfo", userInfo }
    }
}